package qr.server.admin;

import javax.swing.InputVerifier;
import javax.swing.JComponent;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

class InputLengthValidator extends InputVerifier {
	
	private int max;
	
	public InputLengthValidator(int max) {
		this.max = max;
	}
	
	@Override
	public boolean verify(JComponent arg0) {
		JTextField field = (JTextField) arg0;
		boolean valid = ((JTextField) arg0).getText().length() <= this.max;
		
		if (!valid) {
			JOptionPane.showMessageDialog(field, "Name cannot be longer than " + this.max + " characters (for viewability on client).");
		}
		
		return valid;
	}
}
